﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace yule.Common
{
    /// <summary>
    /// 缓存管理
    /// </summary>
    public class CacheManager
    {

        private static object _lock = new object();

        private static Cache.ICacheStrategy _cache = null;
        /// <summary>
        /// 缓存
        /// </summary>
        public static Cache.ICacheStrategy Cache
        {
            get
            {
                if (_cache == null)
                {
                    lock (_lock)
                    {
                        if (_cache == null)
                        {
                            try
                            {
                                string CacheType = yule.Util.AppSettings.GetAppSetting(yule.Const.AppSettings.CacheType);

                                if (yule.Util.Verificate.IsNull(CacheType) == true)
                                {
                                    _cache = new Cache.DefaultCacheStrategy();
                                }
                                else
                                {
                                    _cache = new Cache.RedisCacheStrategy();
                                }
                            }
                            catch
                            {
                                _cache = null;
                            }
                        }
                    }
                }
                return _cache;
            }
        }



    }
}